#include "media/signal/SignalMedia.h"

SignalMedia::SignalMedia(QMap<QString, QMap<QString, QString>> &RGLRLSMAP,
                         QSqlDatabase *DB,
                         QMap<QString, QString> &QSSMAP)
    :MediaLogicGO(RGLRLSMAP, DB, QSSMAP)
{

    connect(&GLOBAL_ARGUR_QTIER, &QTimer::timeout, this, &SignalMedia::basic_configration_init);

    connect(&MULTI_VOLUME_QTIER, &QTimer::timeout, this, &SignalMedia::mdplr_volume_icochange);

    connect(&USER_DLLD_QTIER, &QTimer::timeout, this, &SignalMedia::user_headtimer_hideload);

    connect(BoilPool->mdrs_data_addtion, &MultidatasAddtion::finish, this, &SignalMedia::mtpl_glbreserve_duty); // query anydata be load end after

    connect(BoilPool->mdrs_data_addtion, &MultidatasAddtion::finish, this, [&](){abstract_reserve_loader();}); // query table data be load end after

    connect(BoilPool->mdrs_data_addtion, &MultidatasAddtion::process, this, &SignalMedia::abstract_loader_processing);

    connect(BoilPool->mdrs_data_amend, &MultidatasAmend::finish, this, &SignalMedia::mtpl_resource_loadend);

    connect(BoilPool->mdrs_data_amend, &MultidatasAmend::amend_media_max, this, &SignalMedia::tab_attribute_max);

    connect(BoilPool->mdrs_data_amend, &MultidatasAmend::amend_otherness_update, this, &SignalMedia::mtpl_otherness_assert);

    connect(BoilPool->mdrs_data_amend, &MultidatasAmend::amend_cover_find, this, &SignalMedia::mtpl_backcover_update);

    connect(BoilPool->mdrs_data_del, &MultidatasTake::rmve_finish, this, &SignalMedia::mtpl_resource_removend);

    connect(BoilPool->mdrs_head_crop, &MultidressMaker::headtailor_infosend, this, &SignalMedia::user_head_update);

    connect(&Request, &ResdownLoad::request_process, this, [&](qint64 c, qint64 t){mtpl_resdownload_ds(c, t, DOWN_PROCESS);});

    connect(&Request, &ResdownLoad::request_process_exdwings, this, [&](bool stat){mtpl_resdownload_ds(QVariant(stat), QVariant(), DOWN_PROCESSSTAT);});

    connect(HpforTabLoader, &SecTabload::data_send, this, &MediaLogicCT::tab_viewlayout_init);

    connect(HpforTabLoader, &SecTabload::finished, this, &MediaLogicCT::tab_secload_finish);

    connect(this, &SignalMedia::sg_standar_amend, this,&SignalMedia::mtpl_standar_impactpre);

    connect(this, &SignalMedia::sg_fromtype_amend, this, &SignalMedia::mtpl_viewdata_amend);

    connect(this, &SignalMedia::sg_favoradata_load, this, &SignalMedia::favora_loader);

    connect(this, &SignalMedia::sg_alldata_query, this, &SignalMedia::mtpl_glbreserve_duty);

    connect(&MULTI_DLPL_QTIER, &QTimer::timeout, this, [this]()
    {
        if (impact_int["mdrs-video-index"] < 3)
        {
            mtpl_standar_impactpre(true);
        }
        else
        {
            mtpl_standar_impactpre(false);
        }
        impact_int["mdrs-video-index"] = 0;
    });


    implantation_roof_connect();
    split_roof_connect();
    split_centra_connect();
    whole_left_connect();
    whole_bottom_connect();
    whole_account_connect();
    secondary_assist_connect();
    diary("init successful", Diary::Debug)

    GLOBAL_ARGUR_QTIER.start(); //检测k-lite环境

}

void SignalMedia::implantation_roof_connect(){
    connect(this, &SignalMedia::bsic_icopre, this, [&](){user_implantation_action(CAPBAREXTRA::UI_DATUMINFO);});
    connect(AC_userBar, &QToolBar::actionTriggered, this, [this](QAction *action){user_implantation_action(action);});
    connect(this, &SignalMedia::bsic_ttlepre, this, [&](){user_implantation_action(CAPBAREXTRA::UI_LOGIN);});
}


void SignalMedia::secondary_assist_connect(){
    //右布局以增加2边距解决，备用方案，使用RF_mainWidget\RT_mainWidget 来传点击数据,其中 RT_mainWidget 可能要增加右边边距，否则会与qtablewidget组件的
    //纵向滚动条冲突，最好还是方案1
    connect(LF_mainWidget, &Nwidget::msev_cspre, this, [&](QCursor csor){notify(NTitleBar::Mouse_Press, csor.pos() - pos());});
    connect(LF_mainWidget, &Nwidget::msev_rls, this, [&](QMouseEvent *Event){notify(NTitleBar::Mouse_Release, Event->pos());});
    connect(BT_mainWidget, &Nwidget::msev_cspre, this, [&](QCursor csor){notify(NTitleBar::Mouse_Press, csor.pos() - pos());});
    connect(BT_mainWidget, &Nwidget::msev_rls, this, [&](QMouseEvent *Event){notify(NTitleBar::Mouse_Release, Event->pos());});
    connect(RT_tabWidget, &Nwidget::msev_cspre, this, [&](QCursor csor){notify(NTitleBar::Mouse_Press, csor.pos() - pos());});
    connect(RT_tabWidget, &Nwidget::msev_rls, this, [&](QMouseEvent *Event){notify(NTitleBar::Mouse_Release, Event->pos());});

}

void SignalMedia::split_roof_connect(){
    connect(this, &SignalMedia::bsic_quit, this, &SignalMedia::system_willbe_quit);
    connect(NW_matchComboBox, &NcomboBox::msev_match_pre, this, [&](){QTimer::singleShot(200, this, [&](){network_searchinfo(SEARCHFUNC_INIT);});});
    /*使用QTimer预留缓冲时间，因为点击NW_matchComboBox的搜索按钮会丢失一个点击事件(可能与SCROPED_RESDOWN_ROPEEXEC宏相关，QLoopevent堵塞了点击事件，network_searchexec
    存在多个宏，函数运行完毕后，点击事件才得以释放)，导致意外触发 基类的 notify - move 函数，唤出mask窗口，解决办法为添加QTimer，将事件全释放完毕，再执行
    network_searchexec 函数*/
    connect(NW_blackBoard, &MessageFruitBox::msev_dlcl, this, [&](){QTimer::singleShot(50, this, [&](){network_searchinfo(SEARCHFUNC_DLMDRS);});});
    connect(NW_blackBoard, &MessageFruitBox::msev_trcl, this, [&](){QTimer::singleShot(50, this, [&](){network_searchinfo(SEARCHFUNC_TRYLST);});});
    connect(NW_blackBoard, &MessageFruitBox::msev_back, this, [&](){QTimer::singleShot(50, this, [&](){network_searchinfo(SEARCHFUNC_VIEWBACK);});});
}

void SignalMedia::split_centra_connect(){
    connect(RT_mediaTabWidget, &NTableWidget::doubleClicked, this, &SignalMedia::tab_double_change);
    connect(RT_mediaTabWidget, &NTableWidget::currentCellChanged, this, &SignalMedia::tab_cells_change);
    connect(RT_mediaTabWidget, &NTableWidget::scroll_range, this, &SignalMedia::tab_variant_scroll);
    connect(RT_mediaTabWidget, &NTableWidget::select_range, this, &SignalMedia::tab_unexpeced_select);
    connect(RTP_musicLabel, &NinsipidView::msev_pre, this, [&](){mtpl_viewdata_amend(NT::CUT_MUSIC_TYPE, impact_str["mdrs-sql-filler"]);});
    connect(RTP_moviesLabel, &NinsipidView::msev_pre, this, [&](){mtpl_viewdata_amend(NT::CUT_VIDEO_TYPE, impact_str["mdrs-sql-filler"]);});
    connect(RTP_TbmatchComboBox, &NcomboBox::msev_match_pre, this, [&](){tab_find();});
    connect(RTP_TbmatchComboBox->g_stall(), &NListWidget::itemClicked, this, &SignalMedia::tab_find);
    connect(RTP_update, &NinsipidView::msev_rls, this, &SignalMedia::tab_resource_update);
    connect(RTP_menuLabel->contentMenu(), &QMenu::triggered, this, &SignalMedia::rtp_menu_trigger);
    connect(add_slist, &QMenu::triggered, this, &SignalMedia::rtp_menu_trigger);
    connect(RTP_removeLabel->contentMenu(), &QMenu::triggered, this, &SignalMedia::rtp_menu_trigger);
    connect(RTP_doallplay, &NinsipidView::msev_pre, this, &SignalMedia::mtpl_dall_play);
    connect(RT_videoWidget, &NVideoView::msev_rls, this, &SignalMedia::mtpl_mousev_impactpre);
    connect(RT_videoWidget, &NVideoView::msev_db, this, &SignalMedia::mtpl_mousev_impactpre);
    connect(RT_videoWidget->video_widget, &NVideoWidget::msev_wheel, this, &SignalMedia::mdplr_volumevdo_change);
    connect(RT_videoWidget, &NMainWindow::bsic_quit, this, [&](){MT_MediaPlayer->pause();RT_videoWidget->setVisible(false);});
}

void SignalMedia::whole_left_connect(){
    connect(LF_recordLabel, &NinsipidView::msev_pre, this, [this](){funcdr_relock(NT::CUT_RECORDLOCK);});
    connect(LF_localMeidaLabel, &NinsipidView::msev_pre, this, [this](){funcdr_relock(NT::CUT_LOCALRSLOCK);});
    connect(LF_nearMeidaLabel, &NinsipidView::msev_pre, this, [this](){funcdr_relock(NT::CUT_NEARRSLOCK);});
    connect(Favora_addtionLabel, &NinsipidView::msev_pre, this, [this](){favora_variant(2);});
    connect(Favora_removeLabel, &NinsipidView::msev_pre, this, [this](){favora_variant(0);});
}

void SignalMedia::whole_bottom_connect(){
    connect(MT_MediaPlayer, &QMediaPlayer::positionChanged, this, &SignalMedia::mdplr_plpro_change);
    connect(MT_MediaPlayer, &QMediaPlayer::mediaStatusChanged, this, [this](QMediaPlayer::MediaStatus Stat){mtpl_mddsp_core(Stat, PlayerDFswapKey::UnSwapKey);});
    connect(MT_medialast, &NPlayMask::msev_pre, this, [this](){mtpl_mddsp_core(QMediaPlayer::EndOfMedia, PlayerDFswapKey::PreviousMedia);});
    connect(MT_mediastat, &NPlayMask::msev_pre, this, &SignalMedia::mtpl_mousev_impactpre);
    connect(MT_medianext, &NPlayMask::msev_pre, this, [this](){mtpl_mddsp_core(QMediaPlayer::EndOfMedia, PlayerDFswapKey::NextMedia);});
    connect(RT_videoWidget->mtpl_medialast, &NPlayMask::msev_pre, this, [this](){mtpl_mddsp_core(QMediaPlayer::EndOfMedia, PlayerDFswapKey::PreviousMedia);});
    connect(RT_videoWidget->mtpl_mediastat, &NPlayMask::msev_pre, this, &SignalMedia::mtpl_mousev_impactpre);
    connect(RT_videoWidget->mtpl_medianext, &NPlayMask::msev_pre, this, [this](){mtpl_mddsp_core(QMediaPlayer::EndOfMedia, PlayerDFswapKey::NextMedia);});
    connect(RT_videoWidget->mtpl_durslider, &NSlider::slidervalue, this, [&](double position){MT_MediaPlayer->setPosition(position);});
    connect(MT_tracksSlider, &NSlider::slidervalue, this, [&](double position){MT_MediaPlayer->setPosition(position);});
    connect(MT_mdplermode, &NinsipidView::msev_rls, this, &SignalMedia::mdplr_plmd_change);
    connect(MT_volumeView, &NinsipidView::msev_pre, this, [&](){mdplr_popuplate_fadjusted(0);});
    connect(MT_speedView, &NinsipidView::msev_pre, this, [&](){mdplr_popuplate_fadjusted(1);});
    connect(MT_tracksCover, &Nwidget::msev_pre, this, &SignalMedia::mdplr_lyric_show);
    connect(MT_screen, &NinsipidView::msev_pre, this, [&](){RT_videoWidget->mouseDoubleAssert();});
}

void SignalMedia::whole_account_connect(){
    connect(Login_sumbit, &QPushButton::clicked, this, [this](){user_gearwheel_loginsunmit();});
    connect(Datum_submit, &QPushButton::clicked, this, [this](){user_gearwheel_infosubmit();});
    connect(Register_sumbit, &QPushButton::clicked, this, [this](){user_gearwheel_enrollsubmit();});
    connect(Datum_historyBox->ico(NT::LOCALTION_CENTER_LEFT), &NinsipidView::msev_pre, this, [this](){user_gearwheel_headadd();});
    connect(Register_verifyWin, &NVerificationCode::qrcode_send, this, [&](QString verifi){impact_str["VerificationCode"] = verifi;});
    connect(Datum_historyBox->g_stall(), &QListWidget::currentTextChanged, this, &SignalMedia::user_gearwheel_headgive);
    connect(Datum_head, &NCropLabel::clipsize_send, this, [this](QList<qint64> _Info){user_processing_imginfo("clipsize_send", _Info);});
    connect(Datum_head, &NCropLabel::clipping_send, this, [this](QList<qint64> _Info){user_processing_imginfo("clipping_send", _Info);});
    connect(this, &SignalMedia::sg_userinfo_quit, this, [this](){user_account_quit();});

}









